package com.example.snowli01.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.example.snowli01.R;

import java.util.List;

public class SelectWordAdapter extends BaseAdapter {
    //获取上下文环境
    private Context context;
    //获取item布局
    private int layoutId;
    //数据源
    private List<String> wordList;


    private TextView showWords;

    public SelectWordAdapter(){}

    public SelectWordAdapter(Context context, int layoutId, List<String> wordList) {
        this.context = context;
        this.layoutId = layoutId;
        this.wordList = wordList;
    }


    @Override
    public int getCount() {
        return wordList.size();
    }

    @Override
    public Object getItem(int position) {
        return wordList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        //获取布局文件对象
        View view = LayoutInflater.from(context).inflate(layoutId,null);
        //1.获取布局文件控件对象
        showWords = view.findViewById(R.id.showWords);


        //3.把数据显示到对应控件中去
        if (wordList.get(position).length()>5){
            showWords.setText(wordList.get(position).split("[:]")[1]+":"+wordList.get(position).split("[:]")[2]);
        }

        return view;
    }
}
